#include <iostream>
using namespace std;

struct node
{ int info;
  node * next;
};
  
struct Stack
{ int n;
  node *t;
  Stack()
  { n=0; t=NULL; }
};  

void push(Stack &s, int x)
{ node *p = new node;
  p->info = x;
  p->next = s.t;
  s.t = p;  
  s.n++;  
}

int top(Stack &s)
{ return s.t->info; }

void pop(Stack &s)
{ if(s.t!=NULL)
  { node *p = s.t;
    s.t = p->next;
    delete p;
    s.n--;
  }  
}

void clear(Stack &s)
{ while(s.t != NULL) 
    pop(s);
}


int size(Stack &s)
{ return s.n; }

bool empty(Stack &s)
{ return s.n==0; }

int main()
{ Stack s;  
 
  push(s,10); push(s,15); push(s,12);
  cout << top(s) << endl;
  cout << size(s) << endl;
  pop(s);
  cout << top(s) << endl;
  cout << size(s) << endl;
  push(s,30);
  
  while(!empty(s))
  { cout << top(s) << " ";
    pop(s);
  }  
  cout << endl;
 
  return 0;
}    
    
  
